/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sp.dao.impl;

import java.util.ArrayList;
import java.util.List;
import sp.dao.i.ICategory;
import sp.dao.i.IObjectBase;
import sp.model.Category;

/**
 *
 * @author DINHDV
 */
public class CategoryDAO implements ICategory {

    private IObjectBase iObject;

    public CategoryDAO() {
        iObject = new GenericDAO();
    }

    public boolean insert(Category category) {
        return iObject.insert(category);
    }

    public boolean update(Category category) {
        return iObject.update(category);
    }

    public boolean delete(Category category) {
        return iObject.delete(Category.class, category.getCategoryId());
    }

    public Category getById(int id) {
        return (Category) iObject.getById(Category.class, id);
    }

    public List<Category> getAll() {
        List<Object> objects = iObject.getAll(Category.class);
        List<Category> categories = new ArrayList<Category>();
        for (int i = 0; i < objects.size(); i++) {
            categories.add((Category) objects.get(i));
        }
        return categories;
    }

    public List<Category> filterByFieldName(String filterFieldName, String filterValue) {
        List<Object> objects = iObject.filterByFieldName(Category.class, filterFieldName, filterValue);
        List<Category> categories = new ArrayList<Category>();
        for (int i = 0; i < objects.size(); i++) {
            categories.add((Category) objects.get(i));
        }
        return categories;
    }
}
